<%@ page import="com.scalar.chiptrack.utils.ConfigManager, java.util.Calendar"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/transferMaterial.do?action=transferMaterialReport"/>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>

<HTML><HEAD><TITLE>ScalarSoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
window.onload = init;
var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{
    dateElement.value=passedValue;
    window.focus();
}

function init()
{
    if ( document.transferMaterialform.processStepId  != null)
    {
        qs_1 = new QuickSearch( document.transferMaterialform.processStepId, document.transferMaterialform.qs1, false);
    }
}
function reset()
{
    document.transferMaterialform.reset();
    qs_1.resetQuickSearchCntrl();
}
function selectBaseProduct()
{
	document.transferMaterialform.action="<%=chipTracContext%>/transferMaterial.do?action=transferMaterialReport";
	document.transferMaterialform.submit();
}

function getProductsForProcess()
{
	document.transferMaterialform.action="<%=chipTracContext%>/transferMaterial.do?action=transferMaterialReport";
	document.transferMaterialform.submit();
}
function loadProducts()
{
	document.transferMaterialform.action="<%=chipTracContext%>/transferMaterial.do?action=transferMaterialReport";
	document.transferMaterialform.submit();
}
function validateFromAndToDates()
{
    var formdoc = document.transferMaterialform;
    errMsg = '';

    var pa	= document.getElementById("errors");

    if(chkDate(formdoc.fromDate.value,'From-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.fromDate.focus();
        return false;
    }

    if(chkDate(formdoc.toDate.value,'To-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.toDate.focus();
        return false;
    }

    if(formdoc.fromDate.value!='' && formdoc.toDate.value!='')
    {
        if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.fromDate.value),formatDateAsMMDDYYYY(formdoc.toDate.value)))
        {
            pa.innerHTML = "<li>To Date cannot be less than From Date</li>";
            formdoc.toDate.focus();
            return false;
        }
    }
    return true;
}

function submitForm() // 1 and 2 for EXCEL
{
    var form = document.transferMaterialform;
    var pa	= document.getElementById("errors");

    var d = new Date();
    var day = d.getDate();
    var month = d.getMonth()+1;
    var year = d.getFullYear();
    var hour = d.getHours();
    var min = d.getMinutes();
    var sec = d.getSeconds();

    var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

    var success;

    success = validateFromAndToDates();
    if( form.fromDate.value != '' && success == true  )
    {
        var array = (form.fromDate.value).split("/");
        if ( array[0] < 10 && array[0].length < 2)
            array[0] = "0"+array[0];
        if ( array[1] < 10 && array[1].length < 2 )
            array[1] = "0"+array[1];
        form.fromDate.value = array[0]+"/"+array[1]+"/"+array[2];
    }
    if( form.toDate.value != '' && success == true  )
    {
        var array = (form.toDate.value).split("/");
        if ( array[0] < 10 && array[0].length < 2)
            array[0] = "0"+array[0];
        if ( array[1] < 10 && array[1].length < 2 )
            array[1] = "0"+array[1];
        form.toDate.value = array[0]+"/"+array[1]+"/"+array[2];
    }
    if(success == false)
    {
       return;
    }

    var vendorObj = form.vendorName;
    var vendorName = "";
    var count = 0;

    for( var i = 0 ; i < vendorObj.length; i++ )
    {
        if (vendorObj.options[i].selected)
        {
            count++;
            if ( vendorName != '')
            {
                vendorName = vendorName+","+vendorObj.options[i].value;
            }
            else
            {
                vendorName = vendorObj.options[i].value;
            }
        }
    }

    if( count > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 Vendors only";
		return ;
    }
    form.prompt0.value = vendorName;
    if( form.prompt0.value == '' )
    {
        form.prompt0.value = '0';
    }

   form.action = "<%=chipTracContext%>/transferMaterial.do?action=transferMaterialReportExcel";
   form.submit();

}

function clearErrors()
{
    var pa=document.getElementById("errors");
    pa.innerHTML = "";
}

</script>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<html:form name="transferMaterialform" type="com.scalar.chiptrack.operations.dataentry.lotTransfer.forms.TransferMaterialForm" action="/transferMaterial.do?action=transferMaterialReport">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->


<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/operations/reports_side_menu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>

        <TD valign="top" width="100%">
            <table border="0" width="85%" align="center">
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%" align="center" class="NArialW">Transfer Material Report</TD></TR>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr>
                    <td width="5%">&nbsp;</td>
                    <td width="85%" colspan="5" align="left">
                        <b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b>&nbsp;
                    </td>
                    <input type="hidden" name="prompt0">
                </tr>
                <TR>
                        <TD width="5%">&nbsp;</TD>
                        <TD width="20%" class=NArialL style="width:150px">Process Type</TD>
                        <TD width="25%" class=NArialL >
                        <html:select property="processType" name="transferMaterialform" styleClass="txfield" onchange="getProductsForProcess()" >
                            <html:option value="0">All Process</html:option>
                            <html:options collection="processTypeList" property="value" labelProperty="label"/>
                        </html:select>
                        </TD>
                        <TD width="5%">&nbsp;</TD>
                        <TD width="20%" class=NArialL>Vendor Name</TD>
                        <TD width="25%" class=NArialL>
                         <html:select property="vendorName" name="transferMaterialform" multiple="true" size="4" styleClass="txfield">
                             <option value="0" selected>All Vendors</option>
                            <html:options collection="locationList" property="value" labelProperty="label"/>
                         </html:select>
                        </TD>
                </TR>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <TR>
                        <TD colspan="4">&nbsp;</TD>
                        <TD width="20%" class=NArialL >Quick Search</TD>
                        <TD width="25%" class=NArialL>
                         <input type="text" name="qs1" class="txfield" size='23' onkeyup='quickSearch(qs_1);'/>
                        </TD>
                </TR>

                <TR>
                        <TD width="5%">&nbsp;</TD>
                        <TD width="15%" class=NArialL style="width:150px">Base Product</TD>
                        <TD width="25%" class=NArialL >
                            <html:select property="baseProductId" name="transferMaterialform" styleClass="txfield" onchange="selectBaseProduct()" >
                                <html:option value="0">All Base Products</html:option>
                                <html:options collection="baseProductList" property="value" labelProperty="label"/>
                            </html:select>
                        </TD>
                        <TD width="5%">&nbsp;</TD>
                        <TD width="20%" class=NArialL >Products</TD>
                        <TD width="25%" class=NArialL>
                            <html:select property="processStepId" name="transferMaterialform" styleClass="txfield" >
                                <html:option value="0">All Products</html:option>
                                <html:options collection="partNumberList" property="value" labelProperty="label"/>
                            </html:select>
                        </TD>
                </TR>

               <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=12></td></tr>

                <TR>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="20%" class=NArialL id="fromDate" style="width:100px">From-Date<font color="red">*</font> </TD>
                    <TD width="25%" class=NArialL><font>
                        <html:text property="fromDate" styleClass="txfield" size="16" maxlength="10"/>
                        <a href="javascript:openCalendar(document.transferMaterialform.fromDate)">
                        <img name="fromPickDate" onMouseOver="window.status='Click here to select From date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select From Date"
                        src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="20%" class=NArialL id="asOfDate" style="width:100px">To-Date<font color="red">*</font></TD>
                    <TD width="25%" class=NArialL>
                        <html:text property="toDate" styleClass="txfield" size="16" maxlength="10"/>
                        <a href="javascript:openCalendar(document.transferMaterialform.toDate)">
                        <img onMouseOver="window.status='Click here to select To date';return true" onMouseOut="window.status='';return true" border="0" align='center' title="Click here to Select To Date"
                        src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
                    </TD>
                </TR>
                <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=4>&nbsp;</td></tr>
                <tr>
                    <td colspan="5">&nbsp;</td>
                    <td colspan= "1" align="left" valign="top">
                    <a class="NArialL" href="javascript:submitForm()"  onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
                    </td>
                </tr>
                <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>&nbsp;</td></tr>
                <tr>
                    <td width="30%" colspan="3" align="right"><a href="javascript:submitForm();">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onMouseOver="window.status='Click to Generate Report';return true" onmouseout="window.status='';return true" title="Click here to Generate Report"/></a>
                    </td>
                    <td width="70%"  colspan="3" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:reset();">
                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onMouseOver="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"/></a>
                    </td>
                </tr>
            </table>
            <BR><BR><BR>
        </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
</html:form>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>

<%--
<%
    }
    catch( Exception e )
    {
        e.printStackTrace();
    }
%>--%>
